package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;


/**
 * litemall商品
 *
 * @author yliyun
 * @date 2022/09/22
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("litemall_goods")
public class LitemallGoods  {
    /**
     * 被删除
     */
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    /**
     * 不删除
     */
    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    /**
     * id
     */
    @TableId
    private Integer id;

    /**
     * 商店id
     */
    private Integer shopId;

    /**
     * 商店名字
     */
    private String shopName;

    /**
     * 货物sn
     */
    private String goodsSn;

    /**
     * 名字
     */
    private String name;

    /**
     * 名字在
     */
    private String nameEn;

    /**
     * 类型
     */
    private Byte type;

    /**
     * 小标题
     */
    private String subhead;

    /**
     * 类别id
     */
    private Integer categoryId;

    /**
     * 品牌标识
     */
    private Integer brandId;

    /**
     * 画廊
     */
    private String[] gallery;

    /**
     * 关键字
     */
    private String keywords;

    /**
     * 短暂
     */
    private String brief;

    /**
     * 减价出售
     */
    private Boolean isOnSale;

    /**
     * 商品类型
     */
    private Byte goodsType;

    /**
     * 检查类型
     */
    private Byte reviewType;

    /**
     * 排序顺序
     */
    private Short sortOrder;

    /**
     * 照片url
     */
    private String picUrl;

    /**
     * 分享网址
     */
    private String shareUrl;

    /**
     * 是新
     */
    private Boolean isNew;

    /**
     * 是热
     */
    private Boolean isHot;

    /**
     * 是返回
     */
    private Boolean isReturn;

    /**
     * 是分布
     */
    private Boolean isDistribution;

    /**
     * 分配费用
     */
    private BigDecimal distributionFee;

    /**
     * 价格类型
     */
    private Byte priceType;

    /**
     * 是会员价
     */
    private Boolean isVipPrice;

    /**
     * 活动价格
     */
    private Boolean isActivityPrice;

    /**
     * 单位
     */
    private String unit;

    /**
     * 计数器价格
     */
    private BigDecimal counterPrice;

    /**
     * 零售价格
     */
    private BigDecimal retailPrice;

    /**
     * 操作desc
     */
    private String operationDesc;

    /**
     * 送点
     */
    private BigDecimal giveAwayPoints;

    /**
     * 添加时间
     */
    private LocalDateTime addTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 删除
     */
    @TableLogic
    private Boolean deleted;

    /**
     * 细节
     */
    private String detail;
    private Integer sort;

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        shopId("shop_id", "shopId", "INTEGER", false),
        shopName("shop_name", "shopName", "VARCHAR", false),
        goodsSn("goods_sn", "goodsSn", "VARCHAR", false),
        name("name", "name", "VARCHAR", true),
        nameEn("name_en", "nameEn", "VARCHAR", false),
        type("type", "type", "TINYINT", true),
        subhead("subhead", "subhead", "VARCHAR", false),
        categoryId("category_id", "categoryId", "INTEGER", false),
        brandId("brand_id", "brandId", "INTEGER", false),
        gallery("gallery", "gallery", "VARCHAR", false),
        keywords("keywords", "keywords", "VARCHAR", false),
        brief("brief", "brief", "VARCHAR", false),
        isOnSale("is_on_sale", "isOnSale", "BIT", false),
        goodsType("goods_type", "goodsType", "TINYINT", false),
        reviewType("review_type", "reviewType", "TINYINT", false),
        sortOrder("sort_order", "sortOrder", "SMALLINT", false),
        picUrl("pic_url", "picUrl", "VARCHAR", false),
        shareUrl("share_url", "shareUrl", "VARCHAR", false),
        isNew("is_new", "isNew", "BIT", false),
        isHot("is_hot", "isHot", "BIT", false),
        isReturn("is_return", "isReturn", "BIT", false),
        isDistribution("is_distribution", "isDistribution", "BIT", false),
        distributionFee("distribution_fee", "distributionFee", "DECIMAL", false),
        priceType("price_type", "priceType", "TINYINT", false),
        isVipPrice("is_vip_price", "isVipPrice", "BIT", false),
        isActivityPrice("is_activity_price", "isActivityPrice", "BIT", false),
        unit("unit", "unit", "VARCHAR", false),
        counterPrice("counter_price", "counterPrice", "DECIMAL", false),
        retailPrice("retail_price", "retailPrice", "DECIMAL", false),
        operationDesc("operation_desc", "operationDesc", "VARCHAR", false),
        giveAwayPoints("give_away_points", "giveAwayPoints", "DECIMAL", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false),
        detail("detail", "detail", "LONGVARCHAR", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}